//
//  CollectionView.m
//  HYHoney
//
//  Created by dllo on 16/1/27.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "CollectionView.h"
#import "ModelOfPBL.h"
#import "UIImageView+WebCache.h"
#import "DKNightVersion.h"

@implementation CollectionView

- (instancetype)initWithFrame:(CGRect)frame{

    self = [super initWithFrame:frame];
    
    if (self) {
        
        self.imageV = [[UIImageView alloc] init];
        self.labelForTitle = [[UILabel alloc] init];
        self.labelForDesc = [[UILabel alloc] init];
        
        
        [self.contentView addSubview:self.imageV];
        [self.contentView addSubview:self.labelForTitle];
        [self.contentView addSubview:self.labelForDesc];
    }
    return self;
}


- (void)dealloc{

    [_imageV release];
    [_labelForDesc release];
    [_labelForTitle release];
    [super dealloc];
}


+ (CGFloat)height:(UIImage *)imageT{
    
    CGFloat scale = imageT.size.height / imageT.size.width;
    
    return scale * (([UIScreen mainScreen].bounds.size.width - 30) / 2);
}


- (void)layoutSubviews{

    [super layoutSubviews];
    
    self.imageV.frame = CGRectMake(0, 0, self.bounds.size.width, [self.class height:self.imageV.image]);
    
    
    self.labelForTitle.frame = CGRectMake(0, self.imageV.frame.size.height, self.bounds.size.width, 20);
    self.labelForTitle.numberOfLines = 0;
    self.labelForTitle.font = [UIFont boldSystemFontOfSize:14];
    

    
    self.labelForDesc.frame = CGRectMake(0, self.imageV.frame.size.height + 20, self.bounds.size.width, 40);
    self.labelForDesc.numberOfLines = 0;
    self.labelForDesc.font = [UIFont systemFontOfSize:13];
}



- (void)passmodel:(ModelOfPBL *)model{
                        
    [self.imageV sd_setImageWithURL:[NSURL URLWithString:model.url] placeholderImage:[UIImage imageNamed:@"jzz"]];
    
    self.labelForTitle.text = model.title2;
    self.labelForDesc.text = model.desc;
}


@end
